home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / sep91.zip / 9N09070A < prev    next >
Text File  |  1991-07-10  |  10KB  |  380 lines

  1. /******************************************************
  2.  * Listing 2  hc_util.c
  3.  *
  4.  * HLLAPI utility functions for HOSTCOM .  These
  5.  * functions use the the functions in hc_api.c,
  6.  * Listing 1, and return values that can be used to
  7.  * index into the error message array in hc_error.c,
  8.  * Listing 4.
  9.  *
  10.  ******************************************************/
  11.  
  12. #include <conio.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <dos.h>
  17. #include "hc.h"
  18.  
  19. /* Operator Information Area (OIA) string */
  20. static unsigned char oia_str[103] = "";
  21.  
  22. /******************************************************
  23.  *
  24.  * update_ps() Display Presentation Space
  25.  *
  26.  * return: 0  = successful
  27.  *         1  = not connected to host session
  28.  *         6  = system error encountered
  29.  *
  30.  *****************************************************/
  31.  
  32. int update_ps (char *ps)
  33. {
  34.         int err, x;
  35.         if ((err = copy_ps(ps)) != 0) {
  36.                 switch(err) {
  37.                 case 1:  return(1);
  38.                 case 9:  return(6);
  39.                 }
  40.         }
  41.  
  42.         /* replace NULLs */
  43.         for (x = 0; x < 1920; x++) {
  44.             if (*(ps+x) == 0x00)
  45.                 *(ps+x) = 0x20;
  46.         }
  47.         ps[1920] = '\0';   /* terminate PS string */
  48.  
  49.         write_string(1, 1, ps, norm_attr);
  50.  
  51.         return (0);
  52. }
  53.  
  54. /******************************************************
  55.  *
  56.  * status_msg()  Display status message in the status
  57.  *               area: row 25, column 1.  msg should
  58.  *               be 7 bytes long for consistency.
  59.  *
  60.  *****************************************************/
  61.  
  62. void status_msg(char *msg, int attr)
  63. {
  64.         write_string(1, 25, msg, attr);
  65. }
  66.  
  67.  
  68. /*****************************************************
  69.  *
  70.  * keys_to_host()  Send string of keystrokes to host
  71.  *
  72.  * Not for sending AID keys -- use input_to_host()
  73.  *
  74.  * return: 0 = successful, keys sent
  75.  *         4 = host busy, all keys could not be sent
  76.  *         5 = session inhibited
  77.  *         6 = system error
  78.  *         7 = timeout (from host_wait())
  79.  *         11= invalid parameter
  80.  *
  81.  *****************************************************/
  82.  
  83. int keys_to_host(char *keys)
  84. {
  85.         int err;
  86.  
  87.         if ((err = host_wait()) != 0)
  88.                 return (err);
  89.  
  90.         err = send_key(keys);
  91.  
  92.         switch (err) {
  93.                 case 0:  return(0);
  94.                 case 1:  return(1);
  95.                 case 2:  return(11);
  96.                 case 4:  return(4);
  97.                 case 5:  return(5);
  98.                 case 9:  return(6);
  99.         }
  100. }
  101.  
  102.  
  103. /*****************************************************
  104.  *
  105.  * input_to_host()  Send AID key to the host.
  106.  *
  107.  * Resends the string if the host reports it is busy.
  108.  * User has option to break out with ESC.
  109.  *
  110.  * return: 0 =  successful
  111.  *         4 =  host busy
  112.  *         6 =  system error
  113.  *         7 =  timeout
  114.  *         8 =  invalid parameter
  115.  *         10 = keyboard locked
  116.  *
  117.  *****************************************************/
  118.  
  119.  int input_to_host(char *keys)
  120.  {
  121.         int err;
  122.         int x = 0;
  123.         char status[] = " TIME ";
  124.         char no_time[11] = "";
  125.  
  126.         status_msg("Sending", send_attr);
  127.         if ((err = keys_to_host(keys)) != 5)
  128.                 return(err);
  129.  
  130.         /* HLLAPI code 5: input inhibited; task
  131.          * requires additional time.  Send reset, then
  132.          * resend string until successful or
  133.          * interrupted by user.
  134.          */
  135.  
  136.         while (1) {
  137.         /* Send reset; exit on error.  Only busy (4)
  138.          * and system error (9) are expected.
  139.          * keys_to_host() is not used to avoid call
  140.          * to host_wait().
  141.          */
  142.                 if ((err = send_key("@R")) != 0) {
  143.                         switch (err) {
  144.                                 case 4: return (4);
  145.                                 case 9: return (6);
  146.                         }
  147.                 }
  148.  
  149.                 itoa(++x, no_time, 10);
  150.                 strcat(no_time, status);
  151.                 status_msg(no_time, time_attr);
  152.                 delay(2000);    /* wait two seconds */
  153.  
  154.                 if (receive_esc())
  155.                    return (0); /* user interrupt */
  156.  
  157.                 /* resend key; if other than
  158.                  * inhibited error, return */
  159.                 if ((err = send_key(keys)) != 5) {
  160.                         switch (err) {
  161.                         case 0: return (0);
  162.                         case 1: return (1);
  163.                         case 2: return (8);
  164.                         case 4: return (4);
  165.                         case 9: return (6);
  166.                         }
  167.                 }
  168.         }
  169.  }
  170.  
  171. /*****************************************************
  172.  *
  173.  * host_wait() Wait until host is ready and manage
  174.  *             the display of the status message.
  175.  *
  176.  * return: 0  = system ready
  177.  *         10 = keyboard locked
  178.  *         6  = system error
  179.  *         7  = timeout
  180.  *
  181.  *****************************************************/
  182.  
  183. int host_wait(void)
  184. {
  185.         int err;
  186.         status_msg("Waiting", wait_attr);
  187.         err = wait();
  188.         status_msg("Ready  ", stat_attr);
  189.         switch (err) {
  190.                 case 0: return (0);
  191.                 case 1: return (22);
  192.                 case 4: return (7);
  193.                 case 5: return (10);
  194.                 case 9: return (6);
  195.         }
  196. }
  197.  
  198. /*****************************************************
  199.  *
  200.  * find_msg() Determine if msg is displayed anywhere
  201.  *            in the presentation space.
  202.  *
  203.  * return: 0  = msg was not found
  204.  *        -1  = msg was found
  205.  *         1  = not connected to host session
  206.  *         6  = system error
  207.  *         9 = invalid parameter passed to HLLAPI
  208.  *
  209.  *****************************************************/
  210.  
  211. int find_msg(char *msg)
  212. {
  213.         int str_pos = 0; /* starting search psn */
  214.         int err;
  215.  
  216.         if ((err = search_ps(msg, &str_pos)) != 0) {
  217.                 switch (err) {
  218.                         case 1: return(1);
  219.                         case 2: return(9);
  220.                         case 9: return(6);
  221.                 }
  222.         }
  223.  
  224.         if (str_pos == 0)
  225.                 return(0);      /* not found */
  226.         else
  227.                 return (-1);    /* found */
  228. }
  229.  
  230. /*****************************************************
  231.  *
  232.  * dspy_oia() Display the Operator Information Area.
  233.  *
  234.  * Return  0 = successful
  235.  *         1 = not connect to host session
  236.  *         6 = system error
  237.  *
  238.  *****************************************************/
  239.  
  240. int dspy_oia(void)
  241. {
  242.         int err, y, x = 0;
  243.  
  244.         if ((err = copy_oia(oia_str)) < 9) {
  245.                 gotoxy(1,5);
  246.                 do {
  247.                         for (y=0; y<10; y++) {
  248.                           printf("%5X", oia_str[x++]);
  249.                            if (x == 103)
  250.                                 break;
  251.                         }
  252.                         printf("\n");
  253.                 } while (x < 103);
  254.  
  255.                 return(0);
  256.         }
  257.         else {
  258.                 switch(err) {
  259.                         case 1: return(1);
  260.                         case 9: return(6);
  261.                 }
  262.         }
  263. }
  264.  
  265. /*****************************************************
  266.  *
  267.  * check_power() Determine if session powered on.
  268.  *
  269.  * Checks third byte in OIA which is 0xCD if powered
  270.  * on and 0x00 if powered off.
  271.  *
  272.  * Note:  required for RabbitGATE only
  273.  *
  274.  *****************************************************/
  275.  
  276. int check_power(void)
  277. {
  278.         if (copy_oia(oia_str) < 9) {
  279.                 if ( *(oia_str+2) == 0xCD)
  280.                         return (1);  /* powered on */
  281.                 else
  282.                         return (0);  /* powered off */
  283.         }
  284.         else
  285.                 return(6);
  286. }
  287.  
  288.  
  289. /*****************************************************
  290.  *
  291.  * check_signon()
  292.  *
  293.  * Determine if the session is currently signed on to
  294.  * mainframe application.
  295.  *
  296.  * The fourth byte in the OIA is 0xCF when signed on,
  297.  * and 0xF0 when not signed on, and (for RabbitGATE
  298.  * only) 0x00 when session powered off
  299.  *
  300.  * Return: 1 = signed on,
  301.  *         0 = not signed on.
  302.  *
  303.  *****************************************************/
  304.  
  305. int check_signon(void)
  306. {
  307.         if (copy_oia(oia_str) < 9) {
  308.  
  309.                 if (*(oia_str+3) == 0xCF)
  310.                         return (1);   /* logged in */
  311.                 else
  312.                         return (0);   /* logged out */
  313.         }
  314.         return (6);     /* error */
  315. }
  316.  
  317.  
  318. /*****************************************************
  319.  *
  320.  * connect_ps_space() Connect Presentation Space
  321.  *
  322.  * Return: 0 = successful
  323.  *         2 = invalid PSID
  324.  *         6 = system error
  325.  *         12 = resource unavailable (occurs with
  326.  *              IBM Entry Level only)
  327.  *****************************************************/
  328.  
  329. int connect_ps_space(void) {
  330.         int err;
  331.  
  332.         err = connect_ps();
  333.         switch (err) {
  334.                 case 1:  return(2);
  335.                 case 9:  return(6);
  336.                 case 11: return(12);
  337.                 default: return(0);
  338.         }
  339. }
  340.  
  341. /*****************************************************
  342.  *
  343.  * display_cursor() Display Cursor
  344.  *
  345.  * return: 0  = successful
  346.  *         1  = not connected to session
  347.  *         6  = system error
  348.  *         13 = bad PSID
  349.  *
  350.  *****************************************************/
  351.  
  352. int display_cursor(void) {
  353.         int err;
  354.  
  355.         err = dspy_cursor();
  356.  
  357.         switch (err) {
  358.                 case 0: return(0);
  359.                 case 1: return(1);
  360.                 case 2: return (13);
  361.                 case 9: return(6);
  362.         }
  363. }
  364.  
  365. /*****************************************************
  366.  *
  367.  * reset_connection() Break connection between program
  368.  *   and host, and reset HLLAPI interface
  369.  * Return: 0 = successful
  370.  *         6 = System error
  371.  *****************************************************/
  372.  
  373. int reset_connection(void) {
  374.  
  375.         if (reset() > 0)
  376.                 return(6);
  377.         else
  378.                 return(0);
  379. }
  380.